#pragma once
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include "LogMsg.h"
namespace DDS_PARAMETER {
	enum ReturnCode;
	struct DDS_Attribute;
};
class CPublisher {
public:
	class PublisherListener : public eprosima::fastdds::dds::DataWriterListener
	{
	public:
		PublisherListener();
		~PublisherListener() override;

		void on_publication_matched(
			eprosima::fastdds::dds::DataWriter* writer,
			const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;
		bool has_subscriber();
	private:
		int matched_;
	};

public:
	CPublisher(eprosima::fastdds::dds::DomainParticipant* participant);
	~CPublisher();
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic, std::string profile);
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic, const DDS_PARAMETER::DDS_Attribute& dds_attr);
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic);
	bool has_matched();
	DDS_PARAMETER::ReturnCode publish(std::string topic_name, 
		const uint32_t& index, const uint64_t& timestamp, const std::string& msg);
private:
	PublisherListener m_listener_;
	eprosima::fastdds::dds::Publisher* m_publisher_;
	eprosima::fastdds::dds::DomainParticipant* m_participant_;
};